package com.museum.demo.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.museum.demo.Interface.Result;
import com.museum.demo.Interface.ResultCode;
import com.museum.demo.Service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api("用户操作")
@RequestMapping(value = "/User")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "数据库中插入一个新用户")
    @GetMapping("/insertUser")
    @ApiImplicitParams({@ApiImplicitParam(name = "username",value = "用户名"),
            @ApiImplicitParam(name = "sex",value = "用户性别"),
            @ApiImplicitParam(name = "psw",value = "用户密码")})
    public Result InsertUser(String username, String sex, String psw){
        try {
            userService.InsertUser(username, sex, psw);
            return Result.Success();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @ApiOperation(value = "用户登录操作")
    @GetMapping("/login")
    public Result Login(String username, String password){
        int respone;
        try{
            respone = userService.Login(username, password);
            return Result.Success(respone);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
